package multithreading.pool;

import java.util.concurrent.*;

public class Threadpool {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        //通过ThreadPoolExecutor创建一个线程池对象
     ExecutorService pool= new ThreadPoolExecutor(3,5,7,TimeUnit.SECONDS,
             new ArrayBlockingQueue<>(4),Executors.defaultThreadFactory(),new ThreadPoolExecutor.AbortPolicy());
     //1.用线程池来先实现runnable
//     //通过自己定义的runnable类来创建任务线程对象
//     MyRunable A=new MyRunable();
//        pool.execute(new MyRunable());//创建了了一个Runnable线程对象加入线程池
//        pool.execute(A);
//        pool.execute(A);
//        pool.execute(A);//复用前面核心线程
//        pool.execute(A);
//        pool.execute(A);
//        pool.execute(A);
//        pool.execute(A);//核心线程三个任务队列四个七个以后会调用分支线程
//        pool.execute(A);
//        pool.execute(A);//线程队列，等待队列都满了触发拒绝策略
//        pool.shutdown();//运行完线程池关闭
//      //  pool.shutdownNow();//立即关闭
        //2.用线程池来完成callable任务
       Future<String>  f1 = pool.submit(new Text3(100));
        Future<String> f2= pool.submit(new Text3(100));
        Future<String> f3=  pool.submit(new Text3(100));
        Future<String> f4= pool.submit(new Text3(100));
        System.out.println(f1.get());
        System.out.println(f2.get());
        System.out.println(f3.get());
        System.out.println(f4.get());



    }
}
